﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace LotteryAdmin
{
    public class Validate
    {
        static Regex reg = new Regex(@"^[a-zA-Z0-9_]+$");//英数，以及下划线
        static Regex reg_double = new Regex(@"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$");// 正浮点数
        static Regex reg_Name = new Regex(@"^[a-zA-Z0-9_\u4e00-\u9fa5]+$");//汉字，英数，以及下划线
        static Regex reg_num = new Regex(@"^-?\d+$");
        public static bool ValidateInput(string value)
        {
            if (value == string.Empty)
                return true;
            return reg.Match(value).Success;
        }
        public static bool ValidateUserID(string value)
        {
            if (value == string.Empty)
                return true;
            return reg_Name.Match(value).Success;
        }
        public static bool ValidateInputModify(string value)
        {
            return reg.Match(value).Success;
        }
        public static bool ValidateUserIDModify(string value)
        {
            return reg_Name.Match(value).Success;
        }
        public static bool ValidateMoney(string value)
        {
            return reg_double.Match(value).Success;
        }
        public static bool ValidateName(string value)
        {
            if (value == string.Empty)
                return true;
            return reg_Name.Match(value).Success;
        }
        public static bool ValidateNameModify(string value)
        {
            return reg_Name.Match(value).Success;
        }
        public static bool ValidateNums(string value)
        {
            if (value == string.Empty)
                return true;
            return reg_num.Match(value).Success;
        }
        public static bool ValidateNumsModify(string value)
        {
            return reg_num.Match(value).Success;
        }
        public static bool IsZNumber(string inputData)
        {
            if (string.IsNullOrEmpty(inputData))
            {
                return true;
            }
            else
            {
                Regex rex = new Regex(@"^[0-9]\d*$");
                return rex.IsMatch(inputData);
            }
        }
        public static bool IsZNumberModify(string inputData)
        {
            if (string.IsNullOrEmpty(inputData))
            {
                return false;
            }
            else
            {
                Regex rex = new Regex(@"^[0-9]\d*$");
                return rex.IsMatch(inputData);
            }
        }
        public static bool IsZFloatModify(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return false;
            }
            else
            {
                if (value.IndexOf(".") > -1)
                {
                    return reg_double.IsMatch(value);
                }
                else
                {
                    Regex rex = new Regex(@"^[0-9]\d*$");
                    return rex.IsMatch(value);
                }

            }
        }
    }
}
